package com.example.demo.dao;

import com.example.demo.entity.Supplier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SupplierService extends JpaRepository<Supplier, Long> {
    /**
     * 给product_suppliers插入表项
     * @param productId
     * @param supplierId
     */
    @Modifying
    @Query(value = "INSERT into product_suppliers (product_id, suppliers_id) VALUES (?1, ?2)", nativeQuery = true)
    public void addProductSupplier(long productId, long supplierId);

    /**
     * 修改供应商
     * @param productId1
     * @param supplierId1
     * @param supplierId2
     */
    @Modifying
    @Query(value = "UPDATE product_suppliers SET suppliers_id=?3 WHERE product_id=?1 and suppliers_id=?2", nativeQuery = true)
    public void updateProductSupplier(long productId1, long supplierId1, long supplierId2);

    /**
     * 删除product_suppliers表项
     * @param productId
     * @param supplierId
     */
    @Modifying
    @Query(value = "DELETE FROM product_suppliers WHERE product_id=?1 and suppliers_id=?2", nativeQuery = true)
    public void deleteProductSupplier(long productId, long supplierId);

    List<Supplier> findSuppliersByName(String name);

    public void deleteSuppliersById(long id);

    Supplier findSupplierById(long id);

}
